package com.xjgzinfo.usdp.service.impl;

import com.xjgzinfo.usdp.domain.BladeVisualComponent;
import com.xjgzinfo.usdp.repository.BladeVisualComponentRepository;
import com.xjgzinfo.usdp.service.BladeVisualComponentService;
import com.xjgzinfo.usdp.service.dto.BladeVisualComponentDTO;
import com.xjgzinfo.usdp.service.mapper.BladeVisualComponentMapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Optional;

/**
 * Service Implementation for managing {@link BladeVisualComponent}.
 */
@Service
@Transactional
public class BladeVisualComponentServiceImpl implements BladeVisualComponentService {

    private final Logger log = LoggerFactory.getLogger(BladeVisualComponentServiceImpl.class);

    private final BladeVisualComponentRepository bladeVisualComponentRepository;

    private final BladeVisualComponentMapper bladeVisualComponentMapper;

    public BladeVisualComponentServiceImpl(BladeVisualComponentRepository bladeVisualComponentRepository, BladeVisualComponentMapper bladeVisualComponentMapper) {
        this.bladeVisualComponentRepository = bladeVisualComponentRepository;
        this.bladeVisualComponentMapper = bladeVisualComponentMapper;
    }

    @Override
    public BladeVisualComponentDTO save(BladeVisualComponentDTO bladeVisualComponentDTO) {
        log.debug("Request to save BladeVisualComponent : {}", bladeVisualComponentDTO);
        BladeVisualComponent bladeVisualComponent = bladeVisualComponentMapper.toEntity(bladeVisualComponentDTO);
        bladeVisualComponent = bladeVisualComponentRepository.save(bladeVisualComponent);
        return bladeVisualComponentMapper.toDto(bladeVisualComponent);
    }

    @Override
    @Transactional(readOnly = true)
    public Page<BladeVisualComponentDTO> findAll(Pageable pageable) {
        log.debug("Request to get all BladeVisualComponents");
        return bladeVisualComponentRepository.findAll(pageable)
                .map(bladeVisualComponentMapper::toDto);
    }


    @Override
    @Transactional(readOnly = true)
    public Optional<BladeVisualComponentDTO> findOne(Long id) {
        log.debug("Request to get BladeVisualComponent : {}", id);
        return bladeVisualComponentRepository.findById(id)
                .map(bladeVisualComponentMapper::toDto);
    }

    @Override
    public void delete(Long id) {
        log.debug("Request to delete BladeVisualComponent : {}", id);
        bladeVisualComponentRepository.deleteById(id);
    }
}
